package com.ruoyi.nucleic.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.nucleic.dto.RegisterDto;
import com.ruoyi.nucleic.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/register")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/handleRegister" ,method = RequestMethod.POST)
    public AjaxResult register(@RequestBody RegisterDto registerDto){
        userService.register(registerDto);
        return AjaxResult.success();
    }

}

//    /**
//     * 注册
//     * @param
//     */
//    @Override
//    @Transactional
//    public void userRegister(UserRegisterDto userRegisterDto) {
//        //获取前端传值
//        String address = userRegisterDto.getAddress();
//        Long building_id = userRegisterDto.getBuildingId();
//        Long community_id = userRegisterDto.getCommunityId();
//        String phone = userRegisterDto.getPhone();
//        String sex = userRegisterDto.getSex();
//        String username = userRegisterDto.getUsername();
//        String wx = userRegisterDto.getWx();
//
//
//        //查询user表
//        User user1 = selectByPhone(phone);
//        //判断
//        if (user1==null){
//            //保存到user表
//            User user = new User();
//            user.setAddress(address);
//            user.setPhone(phone);
//            user.setSex(sex);
//            user.setPassword("123456");
//            user.setBuildingId(building_id);
//            user.setCommunityId(community_id);
//            user.setWx(wx);
//            user.setUsername(username);
//            userMapper.insertUser(user);
//            //保存到住户表
//            Resident resident = new Resident();
//            resident.setAddress(address);
//            resident.setBuildingId(building_id);
//            resident.setCommunityId(community_id);
//            resident.setName(username);
//            resident.setPhone(phone);
//            residentMapper.insertResident(resident);
//        }else if (user1.getPhone().equals(phone)){
//            throw new RuntimeException("用户已存在");
//        }
//
//    }
//
//    /**
//     * 查电话
//     * @param phone
//     * @return
//     */
//    private User selectByPhone(String phone) {
//        return userMapper.selectByPhone(phone);
//    }
//}